// 声明一个名为 apiRouter 的子路由
var express = require('express')
var apiRouter = express.Router()
var PageData = require('../model/PageData')
var appData = require('../data/JSONData.json')
// 在子路由上加路径
apiRouter.post('/GetTableData', function (req, res) {

    var pageData = GetPageData(req)
    res.json(pageData)
});

function GetPageData(req) {

    let start = 0,
        pageSize = parseInt(req.body.rows),
        pageIndex = parseInt(req.body.page);




    start = (pageIndex - 1) * pageSize
    let end = start + pageSize;
    appData.rows.sort(function (a, b) {
        return parseInt(a.id) - parseInt(b.id)
    })
    let partData = appData.rows.slice(start, end)

    return new PageData(partData, pageIndex, req.body.sidx, req.body.sord, appData.rows.length, pageSize)

}

module.exports = apiRouter




